package com.baturu.vin.honda.dal.dao;

import com.baturu.vin.honda.dto.HondaPartsImageDTO;
import com.baturu.vin.honda.dto.HondaPartsInfoDTO;
import org.apache.ibatis.annotations.Param;
import org.apache.ibatis.annotations.Select;

import java.util.Collection;
import java.util.List;

/**
 * 本田配件图片DAO
 * @author jiangxinlei
 */
public interface HondaPartsImageDAO {

    @Select({"<script>select distinct illustrationNumber, partReferenceNumber, max_x as bottomRightX, max_y as bottomRightY, min_x as topLeftX, min_y as topLeftY, npl from honda_parts_image",
            "where (illustrationNumber, npl, partReferenceNumber) in ",
            "<foreach item = 'partsInfo' index = 'index' collection = 'partsInfos' open = '(' separator = ',' close = ')'>",
                "(#{partsInfo.nplblk},#{partsInfo.npl},#{partsInfo.nplpartref})",
            "</foreach>",
            "and disk = #{disk}",
            "</script>"})
    List<HondaPartsImageDTO> findImageInfos(@Param("partsInfos") List<HondaPartsInfoDTO> partsInfos, @Param("disk") String disk);

    @Select({"<script>select distinct illustrationNumber, partReferenceNumber, max_x as bottomRightX, max_y as bottomRightY, min_x as topLeftX, min_y as topLeftY from honda_parts_image",
            "where npl = #{npl}",
            "and disk=#{disk}",
            "and illustrationNumber in ",
            "<foreach item='item' index='index' collection='imageNames' open='(' separator=',' close=')'>",
            "#{item}",
            "</foreach>",
            "</script>"})
    List<HondaPartsImageDTO> findImageInfoByImageNameAndNpl(@Param("imageNames") Collection<String> imageNames,
                                                            @Param("npl") String npl,
                                                            @Param("disk") String disk);

}
